<template>
    <div class="box">
        <div class="swiper">
            <el-carousel :interval="5000" arrow="always" height="200px" indicator-position="none">
                <el-carousel-item v-for="item in banner" :key="item.material_id">
                    <img :src='`https:${item.img_url}`'>
                </el-carousel-item>
            </el-carousel>
        </div>
        <div class="tabs">
            <div class="item" v-for="item in tabs" :key="item.material_id">
                <img :src='`https:${item.img_url}`'>
            </div>
        </div>
        <div class="product">
            <div class="product_item" v-for=" item in  newarr" :key="item.action.path">
                <router-link :to="{ name: 'info', params: { id: item.action.path } }">
                    <img :src="item.img_url"></router-link>

                <h3>{{ item.product_name }}</h3>
                <p class="info">{{ item.product_brief }}</p>
                <p class="price">￥{{ item.market_price }}</p>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { homeIntell } from '@/api/home'
import { ref } from 'vue'
import { type maxobj, type Item } from '@/typings'

const total = ref<maxobj>()
const banner = ref<Array<Item>>([])
const tabs = ref<Array<Item>>([])
const newarr = ref<Array<Item>>([])
const hhh = async () => {
    let data = await homeIntell()
    total.value = data

    banner.value = data.data.sections[0].body.items
    tabs.value = data.data.sections[2].body.items.concat(data.data.sections[3].body.items)
    let arr = [];

    for (let i = 0; i < data.data.sections.length; i++) {
        if (data.data.sections[i].view_type == "list_three_type4") {
            arr.push(data.data.sections[i].body.items);
        }
    }

    for (let j = 0; j < arr.length; j++) {
        for (let k = 0; k < arr[j].length; k++) {
            newarr.value.push(arr[j][k]);
        }
    }
    // console.log(newarr.value);




}
hhh()
</script>

<style scoped>
.box {
    background-color: #f4f5f7;
}

img {
    width: 100%;
}

.swiper {
    margin-top: 5px;
}

.el-carousel__item img {
    width: 100%;
    height: 100%;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
    background-color: #d3dce6;
}


.tabs {
    display: flex;
    flex-wrap: wrap;
}

.item {
    width: 78px;
    height: 80px;

}

.product {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 46px;
}

.product_item {
    width: 30vw;
    border-radius: 13px;
    overflow: hidden;
    background-color: #ffffff;
    text-align: center;
    margin-top: 10px;
}

.product_item h3 {
    font-size: 16px;
    font-family: Arial, Helvetica, sans-serif;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    overflow: hidden;
}

.product_item .info {
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    overflow: hidden;
    padding: 0;
}

.product_item .price {
    color: #f56c8c;
}</style>